package com.rivercloud.dao.Impl;

import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.rivercloud.dao.TemplateColDao;
import com.rivercloud.entity.TemplateCol;

public class TemplateColDaoImpl implements TemplateColDao {
	 static SqlSessionFactory sqlSessionFactory = null;
	 static{
		 SqlSessionFactoryBuilder sessionFactoryBuilder = new SqlSessionFactoryBuilder();
		 InputStream inputStream =null;
		 
		 try {
			inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		sqlSessionFactory = sessionFactoryBuilder.build(inputStream);
	 }
	@Override
	public void addTemplateCol(TemplateCol templateCol) {
		SqlSession session = sqlSessionFactory.openSession();
		session.insert("addTemplateCol",  templateCol);
		session.commit();
		session.close();
		
	}
	@Override
	public List<TemplateCol> findByTemplateId(int templateId) {
		try {
			SqlSession session = sqlSessionFactory.openSession();
			List<TemplateCol> list =  session.selectList("findByTemplateId", templateId);
			
			session.close();
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		return null;
	}   
	  

}
